﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

using QuanLyChoVay.Database;
using QuanLyChoVay.Entity;

namespace QuanLyChoVay.Bussiness
{
    class NhanVienBuss
    {
        private DatabaseAccess da;
        public void insertnhanvien(NhanVien nv)
        {
            SqlParameter[] para = new SqlParameter[9];
            para[0] = new SqlParameter("@manv", SqlDbType.Char, 5);
            para[0].Value = nv.Manv;
            para[1] = new SqlParameter("@tendn", SqlDbType.VarChar, 30);
            para[1].Value = nv.Tendn;
            para[2] = new SqlParameter("@matkhau", SqlDbType.VarChar, 30);
            para[2].Value = nv.Matkhau;
            para[3] = new SqlParameter("@hoten", SqlDbType.VarChar, 30);
            para[3].Value = nv.Hoten;
            para[4] = new SqlParameter("@email", SqlDbType.VarChar, 50);
            para[4].Value = nv.Email;
            para[5] = new SqlParameter("@ngaysinh",SqlDbType.Date);
            para[5].Value = nv.Ngaysinh;
            para[6] = new SqlParameter("@diachi", SqlDbType.Char, 50);
            para[6].Value = nv.Diachi;
            para[7] = new SqlParameter("@sdt", SqlDbType.VarChar, 11);
            para[7].Value = nv.Sdt;
            para[8] = new SqlParameter("@quyen", SqlDbType.TinyInt);
            para[8].Value = nv.Quyen;

            da = new DatabaseAccess();
            da.ExecuteProc("NhanVien_insert", para);
        }

        public DataTable select_NhanVien_dangnhap(String tendn, string matkhau)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@tendn", SqlDbType.VarChar, 30);
            para[0].Value = tendn;
            para[1] = new SqlParameter("@matkhau", SqlDbType.VarChar, 30);
            para[1].Value = matkhau;

            da = new DatabaseAccess();
            DataSet ds = new DataSet();
            ds = da.ExecuteProcSelect("NhanVien_selectdangnhap", para);
            DataTable dt = new DataTable();
            dt = ds.Tables[0];

            return dt;
        }

        public DataTable select_NhanVien()
        {
            da = new DatabaseAccess();
            DataSet ds = new DataSet();
            ds = da.ExecuteProcSelect("NhanVien_select", null);
            DataTable dt = new DataTable();
            dt = ds.Tables[0];

            return dt;
        }
        public void update_NhanVien(NhanVien nv)
        {
            SqlParameter[] para = new SqlParameter[9];
            para[0] = new SqlParameter("@manv", SqlDbType.Char, 5);
            para[0].Value = nv.Manv;
            para[1] = new SqlParameter("@tendn", SqlDbType.VarChar, 30);
            para[1].Value = nv.Tendn;
            para[2] = new SqlParameter("@matkhau", SqlDbType.VarChar, 30);
            para[2].Value = nv.Matkhau;
            para[3] = new SqlParameter("@hoten", SqlDbType.VarChar, 30);
            para[3].Value = nv.Hoten;
            para[4] = new SqlParameter("@email", SqlDbType.VarChar, 50);
            para[4].Value = nv.Email;
            para[5] = new SqlParameter("@ngaysinh", SqlDbType.Date);
            para[5].Value = nv.Ngaysinh;
            para[6] = new SqlParameter("@diachi", SqlDbType.Char, 50);
            para[6].Value = nv.Diachi;
            para[7] = new SqlParameter("@sdt", SqlDbType.VarChar, 11);
            para[7].Value = nv.Sdt;
            para[8] = new SqlParameter("@quyen", SqlDbType.TinyInt);
            para[8].Value = nv.Quyen;

            da = new DatabaseAccess();
            da.ExecuteProc("NhanVien_update", para);
        }
    }
}
